home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-06-10 | 4.0 KB | 149 lines | [TEXT/PJMM] |
- {****************************************************}
- {}
- { CGameSwitchboard.p }
- {}
- { Switchboard class, optimized to the needs of gameplay. }
- {}
- { For a real game, you may want to override the Game Switchboard further, }
- { so that mouse clicks, instead of being dispatched to pull down menus etc., }
- { are sent to the gopher as triggers for the ships laser guns (say). }
- {}
- {****************************************************}
-
-
- unit CGameSwitchboard;
-
- interface
-
- uses
- TCL, GameIntf;
-
- implementation
-
-
- {****************************************************}
- {}
- { IGameApp }
- {}
- { Initializes a Game Switchboard object. }
- {}
- {****************************************************}
-
- procedure CGameSwitchboard.IGameSwitchboard;
-
- begin { IGameSwitchboard }
- ISwitchboard;
-
- { Start as a normal, everyday Macintosh application. }
- isInGameMode := FALSE;
-
- { Default to being background friendly, like a normal TCL application. }
- isBackgroundFriendly := TRUE;
- end; { IGameSwitchboard }
-
-
- {****************************************************}
- {}
- { SetInGameMode }
- {}
- { Set the game mode. }
- {}
- {****************************************************}
-
- procedure CGameSwitchboard.SetInGameMode (aInGameMode: Boolean);
-
- begin { SetInGameMode }
- isInGameMode := aInGameMode;
- end; { SetInGameMode }
-
-
- {****************************************************}
- {}
- { GetBackgroundFriendly }
- {}
- { Get the current background friendliness. }
- {}
- {****************************************************}
-
- function CGameSwitchboard.GetBackgroundFriendly: Boolean;
-
- begin { GetBackgroundFriendly }
- GetBackgroundFriendly := isBackgroundFriendly;
- end; { GetBackgroundFriendly }
-
-
- {****************************************************}
- {}
- { SetBackgroundFriendly }
- {}
- { Set the background friendliness. }
- {}
- {****************************************************}
-
- procedure CGameSwitchboard.SetBackgroundFriendly (aBackgroundFriendly: Boolean);
-
- begin { SetBackgroundFriendly }
- isBackgroundFriendly := aBackgroundFriendly;
- end; { SetBackgroundFriendly }
-
-
- {****************************************************}
- {}
- { GetAnEvent }
- {}
- { Gets an event, subject to background friendliness. }
- {}
- {****************************************************}
-
- function CGameSwitchboard.GetAnEvent (var macEvent: EventRecord): Boolean;
-
- begin { GetAnEvent }
- if isBackgroundFriendly then begin
- GetAnEvent := inherited GetAnEvent(macEvent);
- end { if }
- else begin
- { A more obvious approach would be to use GetOSEvent. However, }
- { in spite of what THINK Reference implies, this filters out high }
- { level events; in particular update events. This means that our }
- { windows won't be updated, which is not good. }
- { The next best thing to do is to set a zero sleep time, so no time }
- { is given to background processes. }
- gSleepTime := 0;
- GetAnEvent := inherited GetAnEvent(macEvent);
- end; { else }
- end; { GetAnEvent }
-
-
- {****************************************************}
- {}
- { ProcessEvent }
- {}
- { Process event, subject to the requirement that a Dawdle message be }
- { sent to the Game Director on each iteration of the event loop. }
- { It is assumed that during game play, the Game Director has sole }
- { control the appearance of the mouse; that is, the automatic configuring }
- { of the mouse by TCL can be omitted. }
- {}
- {****************************************************}
-
- procedure CGameSwitchboard.ProcessEvent;
-
- var
- macEvent: EventRecord;
-
- begin { ProcessEvent }
- if not isInGameMode then begin
- inherited ProcessEvent;
- end
- else begin
- if GetAnEvent(macEvent) then begin
- DispatchEvent(macEvent)
- end; { if }
-
- { The Game Director is called to iterate game play in this next call. }
- DoIdle(macEvent);
- end;
- end; { ProcessEvent }
-
-
- end. { CGameSwitchboard }